package com.springark.ms.commons;

import java.util.HashMap;

/**
 * 统一的微服务接口响应类
 * @author hankchan
 * @since 2019/5/8
 */
public class MsApiResult extends HashMap<String, Object> {
    private static final long serialVersionUID = -582836662945770584L;

    public static MsApiResult newInstance() {
        return new MsApiResult();
    }

    private MsApiResult() {}

    public MsApiResult success(Object data, String requestId) {
        return success(data, 0L, "", requestId);
    }

    public MsApiResult success(Object data, Long code, String msg, String requestId) {
        this.put("data", data);
        this.put("code", code);
        this.put("msg", msg);
        this.put("request_id", requestId);
        return this;
    }

    public MsApiResult error(Long code, String msg, String requestId) {
        this.put("data", null);
        this.put("code", code);
        this.put("msg", msg);
        this.put("request_id", requestId);
        return this;
    }
}
